// 创建cookie   /  修改有可以使用
export const setCookie = (name, content, days = 7) => {
    const date = new Date();
    // 解决8小时的时差
    date.setHours(date.getHours() - 8);
    // 把到期时间设置到days天以后
    date.setDate(date.getDate() + days);
    document.cookie = `${name}=${content};path=/;expires=${date}`
}

// 获取所有的cookie
export const getCookies = () => {
    const cookies = document.cookie;
    let arr = cookies.split('; ');
    arr = arr.map(item => {
        const arr2 = item.split('=');
        return {
            name: arr2[0],
            content: arr2[1]
        }
    })
    return arr
}


// 获取指定的cookie
export const getCookie = name => {
    const arr = getCookies();
    // 找到数据
    const res = arr.find(item => item.name === name);
    if (res) {
        return res.content
    }
    else {
        return ''
    }
}


// 删除cookie
export const removeCookie = name => {
    setCookie(name, '', -1);
}
